package org.example.code.test2025.one_month;

/**
 * @Title: test0113
 * @Author yxy
 * @Package org.example.code.test2025.one_month
 * @Date 2025/1/13 14:52
 * @description:
 */
public class test0113 {
    public int waysToSplitArray(int[] nums) {
        if(nums == null || nums.length == 0)
            return 0;
        long leftSum=0,rightSum=0;
        int x = 0;
        for (int num : nums) {
            rightSum += num;
        }
        for(int i=0;i<nums.length-1;i++){
            leftSum += nums[i];
            rightSum -= nums[i];
            if(leftSum >= rightSum){
                x++;
            }
        }
        return x;
    }

    public int myAtoi(String s) {
        String str = s.trim();
        if(str.isEmpty()){
            return 0;
        }
        int max = Integer.MAX_VALUE,min = Integer.MIN_VALUE;
        int index = 0,flag = 1;
        long sum = 0;
        if(str.charAt(index)=='-'||str.charAt(index)=='+'){
            if(str.charAt(index)=='-'){
                flag = -1;
            }
            index++;
        }
        while(index < str.length()){
            char c = str.charAt(index);
            if(c>='0' && c<='9'){
                sum = sum*10 + (c-'0');
                index++;
            }else{
                break;
            }
            if(sum>max||sum<min){
                return flag==1?Integer.MAX_VALUE:Integer.MIN_VALUE;
            }
        }
        return (int) (sum*flag);
    }


    public boolean isMatch(String s, String p) {
        int si=0,pi=0;
        while(si<s.length()&&pi<p.length()){
            if(pi+1<p.length()&&p.charAt(pi+1)=='*'){
                if(p.charAt(pi)==s.charAt(si)){
                    while(si<s.length()&&p.charAt(pi)==s.charAt(si)){
                        si++;
                    }
                }
                if(p.charAt(pi)=='.'){
                    si++;
                }
                pi=pi+2;
            }
            else if(s.charAt(si)==p.charAt(pi)){
                si++;
                pi++;
                continue;
            }
            else if(p.charAt(pi)=='.'){
                si++;
                pi++;
                continue;
            }
        }
        return si == s.length() && pi == p.length();
    }



    public static void main(String[] args) {
        test0113 test = new test0113();
//        int[] nums = new int[10000];
//        int k=0;
//        for (int i = 0; i < nums.length; i++) {
//            nums[i] = k;
//            k--;
//        }
//        System.out.println(test.waysToSplitArray(nums));
        System.out.println(test.isMatch("ab",".*"));
    }
}
